package com.itheima.itheima_health.controller.user;

import com.itheima.itheima_health.constant.EmailConstant;
import com.itheima.itheima_health.constant.MessageConstant;
import com.itheima.itheima_health.constant.RedisConstant;
import com.itheima.itheima_health.entity.Result;
import com.itheima.itheima_health.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * 邮箱发送相关代码
 */
@RestController
@RequestMapping("/order")
@Slf4j
@Api(tags = "预约相关代码发送相关接口")
public class OrderController {

    @Autowired
    private OrderService orderService;
    @PostMapping("/submit")
    @ApiOperation("预约提交")
    public Result SubmitOrder(@RequestBody Map ordermap){
        log.info("预约提交:{}",ordermap);
        Integer id = orderService.SubmitOrder(ordermap);
        return new Result(true, MessageConstant.EMAIL_VERIFY_SUCCESS,id);
    }

    @PostMapping("/findById")
    @ApiOperation("预约消息回显")
    public Result findById(Integer id){
        log.info("预约消息回显 预约id:{}",id);
        try{
            Map map = orderService.findById(id);
            //查询预约信息成功
            return new Result(true,MessageConstant.QUERY_ORDER_SUCCESS,map);
        }catch (Exception e){
            e.printStackTrace();
            //查询预约信息失败
            return new Result(false,MessageConstant.QUERY_ORDER_FAIL);
        }
    }
}
